﻿@*
//------------------------------------------------------------------------------
//  此代码版权声明为全文件覆盖，如有原作者特别声明，会在下方手动补充
//  此代码版权（除特别声明外的代码）归作者本人Diego所有
//  源代码使用协议遵循本仓库的开源协议及附加协议
//  Gitee源代码仓库：https://gitee.com/diego2098/ThingsGateway
//  Github源代码仓库：https://github.com/kimdiego2098/ThingsGateway
//  使用文档：https://diego2098.gitee.io/thingsgateway-docs/
//  QQ群：605534569
//------------------------------------------------------------------------------
*@

@page "/admin/session"
@using System.Linq.Expressions;
@using Masa.Blazor.Presets;
@using Microsoft.AspNetCore.Authorization;
@using ThingsGateway.Admin.Application;

@namespace ThingsGateway.Admin.Blazor
@attribute [Authorize]
@inject UserResoures UserResoures
@inherits BaseComponentBase
@layout MainLayout
<AppDataTable TItem="SessionOutput" 
              SearchItem="SessionPageInput"
              AddItem="SessionOutput" EditItem="SessionOutput"
              SearchModel="@_sessionSearch"
              QueryCallAsync="SessionQueryCallAsync"
              IsMenuOperTemplate=false
                IsShowQueryButton>

    <SearchTemplate>
        <MTextField Dense Style="max-width:200px;" HideDetails=@("auto") Class="my-1 mx-2 " @bind-Value="context.Account"
                        Outlined Label=@context.Description(x => x.Account) />
         <MTextField Dense Style="max-width:200px;" HideDetails=@("auto") Class="my-1 mx-2 " @bind-Value="context.Name"
                        Outlined Label=@context.Description(x => x.Name) />
         <MTextField Dense Style="max-width:200px;" HideDetails=@("auto") Class="my-1 mx-2 " @bind-Value="context.LatestLoginIp"
                        Outlined Label=@context.Description(x => x.LatestLoginIp) />
     </SearchTemplate>

     <ItemColOperTemplate>
         <MButton Color="info" Text StopPropagation OnClick=@(()=>ShowVerificatListAsync(context.Item.VerificatSignList))>
             @context.Item.Description(it=>it.VerificatSignList)
         </MButton>
         @if (@UserResoures.IsHasButtonWithRole("syssessionexit"))
        {
            <MButton Color="error" Text OnClick="()=>SessionExitAsync(context.Item.Id)">
                 强退
             </MButton>
        }

    </ItemColOperTemplate>

    <HeaderTemplate>
        <MLabel class="text-subtitle">@context.Text</MLabel>
    </HeaderTemplate>

    <ItemColTemplate>
        @switch (context.Header.Value)
        {
            case nameof(context.Item.OnlineStatus):
                <EnableChip EnabledLabel=在线
                            DisabledLabel=离线
                            Value="context.Item.OnlineStatus">
                </EnableChip>
                break;
            default:
                @context.Value
                break;
        }

    </ItemColTemplate>
</AppDataTable>

<PDrawer @bind-Value="_isShowVerificatSignList" OnCancel="() => _isShowVerificatSignList = false"
         Title=@_sessionOutput.Description(it => it.VerificatSignList)
         Width=@(IsMobile? "100%":1500)>
    @if (_isShowVerificatSignList)
    {
        <AppDataTable @ref="_verificatinfosDatatable" TItem="VerificatInfo" 
                      SearchItem="BasePageInput" AddItem="object" EditItem="object"
                      QueryCallAsync="VerificatQueryCallAsync"
                      DeleteCallAsync="VerificatExitAsync"
                      IsMenuOperTemplate=false IsShowToolbar IsPage=true
                       IsShowDeleteButton=@UserResoures.IsHasButtonWithRole("sysverificatdelete")>

             <ItemColTemplate>
                 @switch (context.Header.Value)
                {
                    case nameof(context.Item.Device):
                        <MChip Class="ma-1">
                            @(context.Item.Device)
                        </MChip>
                        break;
                    case nameof(context.Item.IsOnline):
                        <EnableChip EnabledLabel=在线
                                    DisabledLabel=离线
                                    Value="context.Item.IsOnline">
                        </EnableChip>
                        break;

                    default:
                        @if (context.Header.CellClass?.Contains("text-truncate") == true)
                        {
                            <span title=@context.Value>
                                @context.Value
                            </span>
                        }
                        else
                        {
                            @context.Value
                        }
                        break;
                }

            </ItemColTemplate>

        </AppDataTable>

    }

</PDrawer>

